package code.hkgolden.android.core;

import android.app.Activity;
import android.content.Intent;
import code.framework.android.core.ApplicationContextImpl;
import code.hkgolden.android.activity.ReplyListActivity;
import code.hkgolden.android.activity.TopicListActivity;
import code.hkgolden.android.data.Channel;

import com.google.inject.Singleton;

@Singleton
public class HkgoldenContextImpl extends ApplicationContextImpl implements
		HkgoldenContext {

	@Override
	public Channel getRequestChannel(Activity activity) {
		final Intent i = activity.getIntent();
		return (Channel) i.getSerializableExtra(KEY_CHANNEL);
	}

	@Override
	public void requestTopics(Channel channel, Activity activity) {
		final Intent i = new Intent(activity, TopicListActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		i.putExtra(KEY_CHANNEL, channel);
		activity.startActivity(i);
	}

	@Override
	public int getRequestTopicId(Activity activity) {
		final Intent i = activity.getIntent();
		return i.getIntExtra(KEY_TOPIC_ID, 0);
	}

	@Override
	public int getRequestMaxPage(Activity activity) {
		final Intent i = activity.getIntent();
		return i.getIntExtra(KEY_MAX_PAGE, 0);
	}

	@Override
	public int getRequestPage(Activity activity) {
		final Intent i = activity.getIntent();
		return i.getIntExtra(KEY_PAGE, 0);
	}

	@Override
	public void requestReplies(int id, int page, Activity activity) {
		final Intent i = new Intent(activity, ReplyListActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		i.putExtra(KEY_TOPIC_ID, id);
		i.putExtra(KEY_PAGE, page);
		activity.startActivity(i);
	}

}
